<?php 
namespace Home\Controller;
class MymessageController extends HomeController
{
    public function comment()
    {

    $this->display('User/index');
    }

    public function bbs()
    {
        // $data=M('bbs')->where(array('status'=>'0'))->order('id DESC')->select();
        $_GET['p'] = empty($_GET['p'])?'1':$_GET['p'];
        $m=M('bbs');
        $count = $m->where(array('status'=>'1'))->count();// 查询满足要求的总记录数
        $p=getpage($m,$count,10);
        $list=$m->where(array('status'=>'1'))->order('id DESC')->page($_GET['p'].',10')->select();
        $this->list=$list;
        $this->assign('list',$list);// 赋值数据集
        $this->page=$p->show();
        // $this->assign('msg',$data);
        $this->display('Mymessage/bbs');
    }

    public function privatemsg()
    {
        // 查询私信信息及接收者的姓名及头像信息
        $_GET['p'] = empty($_GET['p'])?'1':$_GET['p'];
        $m= M('private_msg');
        // $user_id = $_SESSION['user']['id'];
        $list = $m->field('p.id pid,p.msg pmsg,p.time ptime,u.name uname,u.headimg_id uimg,h.img_150 img_150,u.id')
                            ->table('hx_private_msg p,hx_user u,hx_headimg h')
                            ->where('p.user_id=u.id AND u.headimg_id = h.id AND p.writer_id='.$_SESSION['user']['id'])
                            ->order('p.id DESC')
                            ->page($_GET['p'].',5')
                            ->select();
        // V($list);

        $count = $m->table('hx_private_msg p,hx_user u,hx_headimg h')
                            ->where('p.user_id=u.id AND u.headimg_id = h.id AND p.writer_id='.$_SESSION['user']['id'])
                            ->count();


        $p=getpage($m,$count,5);
        // $list=$m->where(array('status'=>'0'))->order('id DESC')->page($_GET['p'].',10')->select();
        $this->list=$list;
        // $this->assign('list',$list);// 赋值数据集
        $this->page=$p->show();
        $this->assign('list',$list);
        $this->display('Mymessage/privatemsg');
    }

    public function del_msg()
    {
        $id = I('get.id/d');
        $data = M('private_msg');
        $info = $data->where(array('id'=>$id))->delete();
        if ($info) {
            $this->redirect('privatemsg');
        }
    }
}